package com.yeeverse.sdk.vo;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yeeverse.sdk.api.SdkContext;
import com.yeeverse.sdk.util.RSAUtils;
import org.apache.log4j.Logger;

public class ReqDataVO<T> {

    Logger logger = Logger.getLogger(ReqDataVO.class);

    private String appid;

    private T t;

    public String getAppid() {
        return SdkContext.getCurrentSdk().getAppId();
    }


    public void setT(T t) {
        this.t = t;
    }

    @Override
    public String toString() {
        JSONObject json = new JSONObject();
        String requestStr = JSON.toJSONString(t);
        logger.debug("请求vo内容:" + requestStr);
        try {
            requestStr = RSAUtils.encryptByPublicKey(requestStr, SdkContext.getCurrentSdk().getPrivateKey());
        } catch (Exception e) {
            throw new RuntimeException("请求数据加密异常", e);
        }
        json.put("appid", getAppid());
        json.put("request", requestStr);
        logger.debug("请求包:" + json);
        return json.toString();
    }
}
